<template>
  <view class="left" :style="{top: top, bottom: '101rpx' }">
    <template v-for="item in list" v-if="list && list.length > 0">
      <view class="item" :class="{'active': item.id === selected.id}" :key="item.id" @click="handleMenu(item)">
        <view class="icon">
          <view class="line"> </view>
        </view>
        <view class="name">{{ item.name }}</view>
      </view>
    </template>
    <view class="nothing" v-if="showNothing && list && list.length === 0">暂无相关分类...</view>
  </view>
</template>

<script>
export default {
  props: ['list', 'selected', 'navBar', 'showNothing'],
  data() {
    return {
      /**
       * 主容器定位
       */
      //#ifdef  MP-WEIXIN
      top: (this.navBar.statusBarHeight + this.navBar.navHeight) * 2 + 120 + 'rpx',
      //#endif
      //#ifdef  APP-PLUS
      top: (this.navBar.statusBarHeight + this.navBar.navHeight) * 2 + 95 + 'rpx',
      //#endif
      //#ifdef  H5
      top: (this.navBar.statusBarHeight + this.navBar.navHeight) * 2 + 160 + 'rpx',
      //#endif
      // currentItem: {}
    }
  },
  methods: {
    handleMenu(item) {
      // this.currentItem = item
      this.$emit('selectItem', item)
    }
  },
  watch: {
    // 默认第一个没选中
    // list: {
    //   deep: true,
    //   handler(v) {
    //     if (v.length > 0) {
    //       this.currentItem = v[0]
    //     }
    //   }
    // }
  }
}
</script>

<style scoped lang="scss">
.left {
  width: 220rpx;
  background-image: url('#{$base_url}/mini/bg/cate.png');
  background-repeat: repeat-y;
  background-size: contain;
  position: fixed;
  z-index: 11;
  overflow-y: auto;
  // iso 13底部
  padding-bottom: 80rpx;
  .nothing {
    font-size: 24rpx;
    color: #cccccc;
    padding: 20rpx;
    line-height: 400rpx;
  }
  .item {
    box-sizing: border-box;
    height: 120rpx;
    display: flex;
    align-items: center;
    //border-bottom: 1rpx solid #f7f7f7;
    overflow: hidden;
    font-size: 24rpx;
    &.active {
      background: white;
      border-bottom: 1rpx solid #f7f7f7;
      border-top: 1rpx solid #f7f7f7;
      .name {
        color: $main_color;
      }
      .icon {
        .line {
          background: $main_color;
        }
      }
    }
    .icon {
      width: 40rpx;
      .line {
        width: 10rpx;
        height: 65rpx;
        //background: $main_color;
        border-radius: 10rpx;
        margin-left: -5rpx;
      }
    }
  }
}
</style>
